// =================== 定义全局变量 ======================
let avatarUrl = 'image/avatar01.jpeg'; // 默认头像
let currentArticle; // 当前访问的帖子
let currentConUser; //当前访问的心理咨询师
let currentUserId;  // 当前登录用户
let profileUserId;  // 查看个人信息
let currentIdentity;//当前用户登录的身份
let currentStuUser; //当前访问的学生
let currentIsNoBookingId;//未预约的帖子id
let deleteStuUsername;//删除的学生id


// ============================ 处理导航激活效果 ===========================
function changeNavActive (boardItem) {
    // 判断当前是否为激活状态
    if (boardItem.hasClass('active') == false) {
      let activeLiEl = $('#topBoardList>.active');
      activeLiEl.removeClass('active');
      boardItem.addClass('active');
      console.log('修改');
      // 请求版块中的帖子
      buildArticleList_con();
    }
}

// ============================ 删除导航激活效果 ===========================
function removeNavActive () {
    // 判断当前是否为激活状态
    let activeLiEl = $('#topBoardList>.active');
    if (activeLiEl) {
      activeLiEl.removeClass('active');
    }
}

//======================= 学生处理导航栏点击并获取帖子列表 ======================
function buildArticleList (){
  console.log('++++++++++++');
  console.log('发送请求查询帖子列表');
  $('#bit-forum-content').load('article_list.html');
}


function buildConUserList (){
  console.log('++++++++++++');
  console.log('发送请求查询帖子列表');
  $('#bit-forum-content').load('article_list.html');
}


//======================= 咨询师处理导航栏点击并获取帖子列表 ======================
function buildArticleList_con (){
  console.log('咨询师++++++++++++');
  console.log('发送请求查询帖子列表');
  $('#bit-forum-content').load('article_list_con.html');
}

//======================= 管理员处理导航栏点击并获取帖子列表 ======================
function buildArticleList_adm (){
  console.log('管理员++++++++++++');
  console.log('发送请求查询帖子列表');
  $('#bit-forum-content').load('article_list_adm.html');
}

//======================= 学生处理导航栏点击预约记录并获取列表 ======================
function buildBookingList (){
  $('#bit-forum-content').load('details_con.html');
}



// 设置站内信接收用户信息
function setMessageReceiveUserInfo (userId, nickname) {
  console.log('userId = ' + userId);
  console.log('nickname = ' + nickname);
  $('#index_message_receive_user_id').val(userId);
  $('#index_message_receive_user_name').html('发送给: <strong>' + nickname + '</strong>');
  console.log('value = ' + $('#index_message_receive_user_id').val());
}


function hidePopup(){
  var overlay = document.getElementById("overlay");
  overlay.style.display = "none";
}



function deleteRow(row) {
  console.log('查看row的内容');
  var value = $(row).parent().parent().find("td");
  deleteStuUsername = value.eq(0).text();
  console.log(deleteStuUsername);
 

  $.ajax({
    type : 'get',
    url : 'stu/update',
    data : {username : deleteStuUsername},
    success : function (respDate) {
      if(respDate.code == 0) {
        console.log('查询咨询师');
        //deleteStuId = row.username;
        var tr = row.parentNode.parentNode;
        tr.parentNode.removeChild(tr);
        $.toast({
          heading: '成功',
          text: '删除成功',
          icon: 'success' 
        });
      } else {
        $.toast({
          heading: '警告',
          text: respDate.message,
          icon: 'warning' 
        });
      }
    },
    error : function() {
      $.toast({
        heading: '错误',
        text: '服务器错误，请联系管理员',
        icon: 'error' 
      });
    }
  });
}


function deleteRowCon(row) {
  console.log('查看row的内容');
  var value = $(row).parent().parent().find("td");
  deleteConUsername = value.eq(0).text();
  console.log(deleteStuUsername);
 

  $.ajax({
    type : 'get',
    url : 'con/update',
    data : {username : deleteConUsername},
    success : function (respDate) {
      if(respDate.code == 0) {
        console.log('查询咨询师');
        //deleteStuId = row.username;
        var tr = row.parentNode.parentNode;
        tr.parentNode.removeChild(tr);
        $.toast({
          heading: '成功',
          text: '删除成功',
          icon: 'success' 
        });
      } else {
        $.toast({
          heading: '警告',
          text: respDate.message,
          icon: 'warning' 
        });
      }
    },
    error : function() {
      $.toast({
        heading: '错误',
        text: '服务器错误，请联系管理员',
        icon: 'error' 
      });
    }
  });
}